package cmd

import (
	"github.com/urfave/cli/v2"
)

// AppInfo
//
// 配置 cmd 信息
type AppInfo struct {
	Name    string
	Version string
}

// Flags
//
// cmd 的 flag 信息
type Flags struct {
	files string
	conf  string
	port  int
}

func AppInit(a *AppInfo) *cli.App {

	app := &cli.App{}

	app.Name = a.Name
	app.Version = a.Version
	app.Usage = "A easy way to manage document files"

	app.Commands = []*cli.Command{
		{
			Name:    "init",
			Aliases: []string{"i"},
			Usage:   "init document manager [dm] in the target folder",
			Flags: []cli.Flag{
				&cli.BoolFlag{
					Name:    "no-run",
					Aliases: []string{"n", "nr"},
					Usage:   "do not replace document files in the root, just generate config file",
				},

				&cli.BoolFlag{
					Name:    "debug",
					Aliases: []string{"d"},
					Usage:   "log the detail of initiation",
				},
			},
			Action: func(c *cli.Context) error {
				return InitCommand(c)
			},
		},

		{
			Name:    "find",
			Aliases: []string{"f", "fd"},
			Usage:   "find documents information in the root",
			Flags: []cli.Flag{
				&cli.IntFlag{
					Name:    "count",
					Aliases: []string{"c"},
					Value:   999999,
					Usage:   "show finding result up to this count",
				},

				&cli.IntFlag{
					Name:    "time",
					Aliases: []string{"t"},
					Value:   0,
					Usage:   "sort result by time, value 0 will do nothing, positive value will sort from old to new, negative value  on the contrary",
				},

				&cli.IntFlag{
					Name:    "size",
					Aliases: []string{"s"},
					Value:   0,
					Usage:   "sort result by size, value 0 will do nothing, positive value will sort from small to large, negative value on the contrary",
				},

				&cli.BoolFlag{
					Name:    "ignore-case",
					Aliases: []string{"ic"},
					Usage:   "ignore the case of the document name",
				},
			},
			Action: func(c *cli.Context) error {
				return FindCommand(c)
			},
		},

		{
			Name:    "add",
			Aliases: []string{"a"},
			Usage:   "add document in the root, use params \".\" will add all documents in the root",
			Action: func(c *cli.Context) error {
				return AddCommand(c)
			},
		},

		{
			Name:    "remove",
			Aliases: []string{"r", "rm"},
			Usage:   "remove document in the root",
			Action: func(c *cli.Context) error {
				return RemoveCommand(c)
			},
		},

		{
			Name:    "update",
			Aliases: []string{"u"},
			Usage:   "update document in the root, with params extname to scan the target folder",
			Action: func(c *cli.Context) error {
				return UpdateCommand(c)
			},
		},

		{
			Name:    "dup",
			Aliases: []string{"d"},
			Usage:   "do the duplicate removal task in the folder",
			Flags: []cli.Flag{
				&cli.BoolFlag{
					Name:    "no-run",
					Aliases: []string{"n", "nr"},
					Usage:   "just scanning not actually deleting files",
				},
			},
			Action: func(c *cli.Context) error {
				return DupCommand(c)
			},
		},

		{
			Name:    "overview",
			Aliases: []string{"o", "ov"},
			Usage:   "see the overview of the root",
			Flags: []cli.Flag{
				&cli.IntFlag{
					Name:    "time",
					Aliases: []string{"t"},
					Value:   0,
					Usage:   "sort result by time, value 0 will do nothing, positive value will sort from old to new, negative value  on the contrary",
				},

				&cli.IntFlag{
					Name:    "size",
					Aliases: []string{"s"},
					Value:   0,
					Usage:   "sort result by size, value 0 will do nothing, positive value will sort from small to large, negative value on the contrary",
				},

				&cli.IntFlag{
					Name:    "count",
					Aliases: []string{"c"},
					Value:   0,
					Usage:   "sort result by the count of files, value 0 will do nothing, positive value will sort small to large, negative value  on the contrary",
				},
			},
			Action: func(c *cli.Context) error {
				return OverviewCommand(c)
			},
		},
	}

	return app
}
